package com.lyf;

import com.lyf.dao.UserDao;
import com.lyf.entity.Emp;
import com.lyf.entity.User;
import com.lyf.factory.MyFactory;
import com.lyf.services.UserService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class test {
    @Test
    public void test7(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("/application_old.xml");
        UserDao e = (UserDao) ac.getBean("ud");
        UserDao e1 = (UserDao) ac.getBean("ud");
        UserDao e2 = (UserDao) ac.getBean("ud");
        System.out.println(e==e1);
        System.out.println(e==e2);

    }
    @Test
    public void test6(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("/application_old.xml");
        UserService e = (UserService) ac.getBean("userService2");
        e.sayHi();
    }
    @Test
    public void test5(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("/application_old.xml");
        Emp e = (Emp) ac.getBean("emp");
        System.out.println(e);
    }


    @Test
    public void test4(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("/application_old.xml");
        User u = (User) ac.getBean("user");
        System.out.println(u);
    }


    @Test
    public void test3(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("/application_old.xml");
        UserService us = (UserService) ac.getBean("userService");
        us.sayHi();
    }

    @Test
    public void test2(){
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/application_old.xml");
        UserDao userDao = (UserDao) applicationContext.getBean("userDao");
        userDao.userInfo();
        UserService userService = (UserService) applicationContext.getBean("userService");
        userService.sayHi();
    }

    @Test
    public void test1(){
        //实例化工厂类
        MyFactory myFactory = new MyFactory();
        UserDao userDao = (UserDao) myFactory.getBean("userDao");
        userDao.userInfo();
    }
}
